﻿package at.geoathome.utils
{
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.getTimer;
	import flash.system.System;
	
	/**
	 * ...
	 * @author Georg Kamptner
	 */
	public class MEMORY extends Sprite {

		public var memory :String = "...";

		public var tf:TextField;
		public var bar:Shape;

		/**
		 *
		 * @return
		 */
		public function MEMORY():void
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		public function onAddedToStage(e:Event = null):void
		{
			bar = new Shape();
			addChild(bar);
			bar.x = stage.stageWidth - 4;
			bar.y = 4;
			
			bar.graphics.beginFill(0xff0000, 0.5);
			bar.graphics.lineStyle();
			bar.graphics.drawRect(0, 0, -120, 15);
			bar.graphics.endFill();

			tf = new TextField();
			addChild(tf);
			tf.x = stage.stageWidth - 123;
			tf.y = 5;
			tf.width = 120;
			tf.height = 18;
			tf.defaultTextFormat = new TextFormat("Arial", 9, 0xffffff);
			tf.alpha = 0.6;
			tf.selectable = false;
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			
			this.mouseChildren = false;
			this.mouseEnabled = false;
		}

		/**
		 *
		 * @param	event
		 * @return
		 */
		private function enterFrameHandler( event:Event ):void
		{
			tf.text = System.totalMemory.toString() + " (" + (System.totalMemory/1024/1024).toString().substr(0, 4) + "MB) - " + System.totalMemory.toString().length;
		}
	}

	
}